package com.example.prison.service.impl;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.prison.entity.PeopleManage;
import com.example.prison.service.PeopleManageService;
import com.example.prison.mapper.PeopleManageMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author jiang
* @description 针对表【people_manage】的数据库操作Service实现
* @createDate 2024-06-03 16:13:21
*/
@Service
public class PeopleManageServiceImpl extends ServiceImpl<PeopleManageMapper, PeopleManage>
    implements PeopleManageService{


    @Autowired
    private PeopleManageMapper peopleManageMapper;

    @Override
    public PageInfo<PeopleManage> get(int pageNumber, int pageSize,
                                      String name, String unit, String post, String status, String phone, String idCard) {
        PageHelper.startPage(pageNumber, pageSize);
        return new PageInfo<>(peopleManageMapper.get(name, unit, post, status, phone, idCard));
    }

    @Override
    public int add(PeopleManage data) {
        String id_card = data.getIdCard();
        if (ObjectUtils.isNotEmpty(peopleManageMapper.getListByIdCard(id_card))) {
            return -1;
        } else {
            peopleManageMapper.add(data);
            return 1;
        }
    }

    @Override
    public int delete(Integer[] ids) {
        peopleManageMapper.deleting(ids);
        return 1;
    }

    @Override
    public int update(PeopleManage data, Integer departId) {
        PeopleManage departDTO = peopleManageMapper.getById(departId);
        peopleManageMapper.updating(data, departId);
        if (peopleManageMapper.getListByIdCard(data.getIdCard()).size() > 1) {
            peopleManageMapper.updating(departDTO, departId);
            return -1;
        }
        return 1;
    }

    @Override
    public PeopleManage getById(Integer departId) {
        return peopleManageMapper.getById(departId);
    }

    @Override
    public PeopleManage getOnePersonnelByIDCard(String IdCard){
        return peopleManageMapper.getOnePersonnelByIDCard(IdCard);
    }

    @Override
    public List<PeopleManage> getByStatusAndName(String name, String status) {
        return peopleManageMapper.getByStatusAndName(name, status);
    }

    @Override
    public List<PeopleManage> getOneListByName(String name) {
        return peopleManageMapper.getOneListByName(name);
    }

    @Override
    public List<PeopleManage> getByPost(String name) {
        return peopleManageMapper.getByPost(name);
    }

    @Override
    public List<PeopleManage> getByUnit(String unit){
        return peopleManageMapper.getByUnit(unit);}

    @Override
    public PeopleManage getByPID(String pid){
        return peopleManageMapper.getByPID(pid);
    }


}




